package com.yanqu.road.server.cmd.beautyescort;

import com.yanqu.road.pb.beautyescort.BeautyEscortProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.beautyescort.CrossBeautyEscortMgr;
import com.yanqu.road.server.manager.beautyescort.CrossEscortPlayerWrap;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_BEAUTY_ESCORT_ATTACK_EVENT_BOSS, desc = "攻击恶人")
public class CrossBeautyEscortAttackEventBossCmd extends CrossCommand {

    int cartId;
    long dartId;
    long playerId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BeautyEscortProto.BeautyEscortAttackEventBossReqMsg reqMsg = BeautyEscortProto.BeautyEscortAttackEventBossReqMsg.parseFrom(packet.getBytes());
        cartId = reqMsg.getCartId();
        dartId = reqMsg.getDartId();
        playerId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossEscortPlayerWrap escortPlayer = CrossBeautyEscortMgr.getEscortPlayer(serverId, packet.getPlayerId());
        if(escortPlayer != null){
            ret = escortPlayer.attackBoss(cartId, dartId);
        }
    }

    @Override
    public void sendData() {
        if(ret != 0){
            BeautyEscortProto.BeautyEscortAttackEventBossRespMsg.Builder respMsg = BeautyEscortProto.BeautyEscortAttackEventBossRespMsg.newBuilder();
            respMsg.setRet(ret);
            MessageHelper.sendPacket(serverId, playerId, YanQuMessageUtils.buildMessage(Protocol.U_BEAUTY_ESCORT_ATTACK_EVENT_BOSS, respMsg));
        }
    }
}
